package com.snopy.designPattern.observer;

import java.io.File;
import java.io.IOException;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Editor
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/16 16:30
 */
public class Editor {
    public EventManager events;

    private File file;

    public Editor() {
        this.events = new EventManager("open","save");
    }

    public void openFile(String filePath){
        this.file = new File(filePath);
        events.notify("open",file);
    }
    public void saveFile() throws Exception {
        if (file!=null){
            events.notify("save",file);
        }else {
            throw new Exception("Please open a file first!");
        }
    }
}
